package wiki.mdzz.learn_android.components

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import wiki.mdzz.learn_android.R

class TitleLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
    private var titleText: TextView? = null

    init {
        LayoutInflater.from(context).inflate(R.layout.title, this)
        val leftBtn = findViewById<Button>(R.id.leftBtn)
        val rightBtn = findViewById<Button>(R.id.rightBtn)
        leftBtn.setOnClickListener {
            val activity = context as Activity
            activity.finish()
        }

        rightBtn.setOnClickListener {
            Toast.makeText(context, "U clicked Edit", Toast.LENGTH_SHORT).show()
        }

        titleText = findViewById(R.id.titleTextView)
    }

    fun updateTitle(s: CharSequence) {
        titleText?.text = s
    }
}